home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / presto / prest1_0.lha / Tests / exer / locktest.C < prev    next >
C/C++ Source or Header  |  1991-12-11  |  1KB  |  71 lines

  1.  
  2. #include <stdio.h>
  3. #include <stream.h>
  4. #include "presto.h"
  5.  
  6.  
  7. static shared_t int loopcount = 150;
  8.  
  9. int
  10. Main::init()
  11. {    
  12.     nummainthreads = 1;
  13.     for (argc--, argv++; *argv && **argv == '-'; argv++, argc--)
  14.         switch (*(*argv + 1)) {
  15. #ifdef sequent
  16. #ifdef i386
  17.                 case 'a':
  18.                         affinity = 1;
  19.                 break;
  20. #endif /* i386 */
  21. #endif /* sequent */
  22.             case 'q':
  23.                 quantum = atoi(*argv + 2);
  24.                 break;
  25.             case 'n':
  26.                 numprocessors = atoi(*argv + 2);
  27.                 break;
  28.             case 't':
  29.                 nummainthreads = atoi(*argv + 2);
  30.                 break;
  31.             case 'l':
  32.                 loopcount = atoi(*argv + 2);
  33.                 break;
  34.             default:
  35.                 cerr << chr(*(*argv + 1)) << " unknown flag.\n";
  36.                     return -1;
  37.         }
  38.     return 0;
  39. }
  40.  
  41.  
  42.  
  43. static shared_t Lock l("main_lock");
  44. static shared_t int busy = 0;
  45.  
  46. int
  47. Main::main()
  48. {
  49.     int i;
  50.     while (loopcount > 0)    {
  51.         l.lock();
  52.         if (busy)    {
  53.             cout << "Failure.\n";
  54.             abort();
  55.         }
  56.         busy++;
  57.         for (i = 0; i < 5000; i++);
  58.         loopcount--;
  59.         busy--;
  60.         l.unlock();    
  61.     }
  62.     return 0;
  63. }
  64.  
  65. int
  66. Main::done()
  67. {
  68.     cout << "Success.\n";
  69.     return 0;
  70. }
  71.